#include <cstdio>
#define N 500010
using namespace std;
typedef long long ll;
int i,j,k,n,m,x,y,t,p,T;
ll f[N];
ll mi(int x,int y){
	if (y==0)return 1;
	if (y==1)return x;
	ll t=mi(x,y>>1);
	t=(1ll*t*t)%p;
	return y&1?(1ll*x*t)%p:t;
}
ll C(int x,int y){
	if (x>y)return 0;
	return (1ll*(f[y]*mi(f[x],p-2))%p*mi(f[y-x],p-2))%p;
}
ll lucas(int x,int y){
	if (x==0)return 1;
//	printf("%d %d\n",x,y);
	return (1ll*C(x%p,y%p)*lucas(x/p,y/p))%p;
}
int main(){
	scanf("%d",&T);
	scanf("%d%d%d",&n,&m,&p);
	f[0]=1;for (i=1;i<=500000;i++)f[i]=(1ll*i*f[i-1])%p;
	printf("%lld\n",lucas(m,n));
    return 0;
}
//C(n,m)